import { loginTypeEnum, purposeEnum } from '@/types/constants'
import type { LoginResult, ProfileUpdate, UserAuthInfo, University } from '@/types/members'
import { http } from '@/utils/http'

/**
 * 发送验证码
 * @param phone 手机号
 * @returns
 */
export const postTokenSendsms = (phone: string, purpose: purposeEnum) => {
  return http({
    method: 'POST',
    url: '/v1/token/sendsms',
    data: { phone: phone, purpose: purpose },
  })
}
/**
 * 手机号注册
 * @param phone
 * @param password
 * @param verification_code
 * @returns
 */
export const postTokenPhoneRegister = (
  phone: string,
  password: string,
  verification_code: string,
) => {
  return http({
    method: 'POST',
    url: '/v1/token/phoneregister',
    data: { phone: phone, password: password, verification_code: verification_code },
  })
}
/**
 * 用户密码登录
 * @param username
 * @param password
 * @returns
 */
export const postLoginAccessToken = (
  username: string,
  password: string,
  login_type: loginTypeEnum,
) => {
  return http<LoginResult>({
    method: 'POST',
    url: '/v1/login/access-token',
    data: { username, password, login_type },
  })
}

/**
 *  更新用户信息
 * @param data 用户信息
 * @returns
 */
export const putUsersMe = (data: ProfileUpdate) => {
  return http<LoginResult>({
    method: 'PUT',
    url: '/v1/users/me',
    data,
  })
}
/**
 * 获取用户认证信息
 * @returns
 */
export const getUserAuthInfoAPI = () => {
  return http<UserAuthInfo[]>({
    method: 'GET',
    url: `/v1/users/me/authinfo`,
  })
}
//* 获取大学
export const getUniversityByNameAPI = (name: string) => {
  return http<University[]>({
    method: 'GET',
    url: `/v1/university/university?name=${name}`,
  })
}
/**
 * 获取用户信息
 * @returns
 */
export const getUserMeAPI = () => {
  return http<LoginResult>({
    method: 'GET',
    url: `/v1/users/me`,
  })
}
